package com.ruan.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName:RabbitMqConfig
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/7 14:31
 **/
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue smsQueue(){
        return new Queue("sms-queue");
    }

    @Bean
    public CustomExchange smsExchange() {
        return new CustomExchange("sms-exchange", "direct", true, false);
    }

    @Bean
    public Binding smsBinding(Queue smsQueue, CustomExchange smsExchange) {
        return BindingBuilder.bind(smsQueue).to(smsExchange).with("sms-routing-key").noargs();
    }




    @Bean
    public Queue payConfirmQueue(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", "payConfirmDLX"); // 将队列的死信发送到payConfirmDLX交换机
        args.put("x-dead-letter-routing-key", "dead-letter-pay-confirm"); // 指定死信消息的路由键
        return new Queue("pay-confirm-queue",true,false,false,args);
    }

    @Bean
    public DirectExchange payConfirmDLX() {
        return new DirectExchange("payConfirmDLX");
    }

    @Bean
    public Queue deadLetterPayConfirmQueue() {
        return new Queue("dead-letter-pay-confirm-queue", true, false, false);
    }

    @Bean
    public Binding deadLetterBinding() {
        return BindingBuilder.bind(deadLetterPayConfirmQueue()).to(payConfirmDLX()).with("dead-letter-pay-confirm");
    }
    @Bean
    public DirectExchange payConfirmExchange() {
        return new DirectExchange("pay-confirm_directExchange", true, false, null);
    }

    @Bean
    public Binding payConfirmBinding() {
        return BindingBuilder.bind(payConfirmQueue()).to(payConfirmExchange()).with("pay-confirm");
    }

    @Bean
    public Binding payConfirmDLXBinding() {
        return BindingBuilder.bind(deadLetterPayConfirmQueue()).to(payConfirmDLX()).with("dead-letter-pay-confirm");
    }








    @Bean
    public Queue pictureDelayedQueue() {
        return new Queue("orders-delayed-queue");
    }

    @Bean
    public CustomExchange pictureDelayedExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("orders-delayed-exchange", "x-delayed-message", true, false, args);
    }

    @Bean
    public Binding binding(Queue pictureDelayedQueue, CustomExchange pictureDelayedExchange) {
        return BindingBuilder.bind(pictureDelayedQueue).to(pictureDelayedExchange).with("orders-delayed-routing-key").noargs();
    }



}
